/**
 * Copyright (c) 时间, Tal.Ben 袁东昊 (ydonghao2@gmail.com).
 *
 * 版权
 */
package com.talben.soudian.adapter;

import com.talben.soudian.R;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseExpandableListAdapter;
import android.widget.ImageView;
import android.widget.TextView;

/**
 * @Title: MyListAdapter.java
 * @Package com.talben.soudian.adapter
 * @Description: TODO(添加描述)
 * @author Tal.Ben
 * @date 2015年6月3日 下午8:28:43
 * @version v1.0
 */
public class MyListAdapter extends BaseExpandableListAdapter {

	private Context mContext;
	
	private String[][] childs = new String[5][10];
	String[] groups = new String[] { "同步剧场", "搜点出品", "热播电影", "片花速递", "动漫乐园" };
	int[] tags = new int[] { 0, 0, 0, 0, 0 };
	public MyListAdapter(Context mContext) {
		this.mContext = mContext;
		for (int i = 0; i < 5; i++) {
			for (int j = 0; j < 10; j++) {
				this.childs[i][j] = "child" + i + "_" + j;
			}
		}
	}

	@Override
	public String getChild(int arg0, int arg1) {
		// TODO Auto-generated method stub
		return childs[arg0][arg1];
	}

	@Override
	public long getChildId(int arg0, int arg1) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public View getChildView(int arg0, int arg1, boolean arg2, View arg3,
			ViewGroup arg4) {
		// TODO Auto-generated method stub
		if (arg3 == null) {
			arg3 = LayoutInflater.from(mContext).inflate(
					R.layout.list_child_item, null);
		}
		return arg3;
	}

	@Override
	public int getChildrenCount(int arg0) {
		// TODO Auto-generated method stub
		return 10;
	}

	@Override
	public Object getGroup(int arg0) {
		// TODO Auto-generated method stub
		return groups[arg0];
	}

	@Override
	public int getGroupCount() {
		// TODO Auto-generated method stub
		return groups.length;
	}

	@Override
	public long getGroupId(int arg0) {
		// TODO Auto-generated method stub
		return arg0;
	}

	class GroupHolder {
		ImageView img;
		TextView title;
	}

	@Override
	public View getGroupView(int arg0, boolean arg1, View arg2,
			ViewGroup arg3) {
		// TODO Auto-generated method stub
		GroupHolder groupHolder;
		if (arg2 == null) {
			arg2 = LayoutInflater.from(mContext).inflate(
					R.layout.list_group_item, null);
			groupHolder = new GroupHolder();
			groupHolder.img = (ImageView) arg2.findViewById(R.id.tag_img);
			groupHolder.title = (TextView) arg2
					.findViewById(R.id.title_view);
			arg2.setTag(groupHolder);
		} else {
			groupHolder = (GroupHolder) arg2.getTag();
		}
		if (tags[arg0] == 0) {
			groupHolder.img
					.setImageResource(R.drawable.list_indecator_button);
		} else {
			groupHolder.img
					.setImageResource(R.drawable.list_indecator_button_down);
		}
		groupHolder.title.setText(groups[arg0]);

		return arg2;
	}

	@Override
	public boolean hasStableIds() {
		// TODO Auto-generated method stub
		return true;
	}

	@Override
	public boolean isChildSelectable(int arg0, int arg1) {
		// TODO Auto-generated method stub
		return true;
	}
}

